<?php

$pluginName = 'iframeform';
class uploadPlugins_iframeform extends BaseUpload
{
	public function __construct()
	{
		parent::__construct();
	}
	
	public function XHTMLForm()
	{
		return '
<style type="text/css">
.iframeformUp
{
	width: 340px;
	height: 30px;
	display: block;
	margin-left: 50%;
	position: relative;
	left: -150px;
}
</style>
<h3>You can use this form to upload multiple files</h3>
<iframe class="iframeformUp" frameborder="0" longdesc="'.UPLOAD_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'iframeform/up.php" scrolling="no" src="'.UPLOAD_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'iframeform/up.php"></iframe>
<span id="more"></span>
<p><a href="#addMore" onclick="return addAction();">Add another file</a></p>
<script type="text/javascript">
var addAction = function()
{
	$("#more").append("<iframe class=\"iframeformUp\" frameborder=\"0\" longdesc=\"'.UPLOAD_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'iframeform/up.php\" scrolling=\"no\" src=\"'.UPLOAD_PLUGINS_DIRECTORY.OS_PATH_SEPARATOR.'iframeform/up.php\"></iframe>");
	return false;
}
</script>
';
	}
	
	public function process()
	{
		if(isset($_FILES['file']['tmp_name']))
		{
			$this->addUploadedFile(new File($_FILES['file']['tmp_name'], $_FILES['file']['name']));
		}
		else
		{
			throw new Exception('No file have been uploaded');
		}
		return parent::process();
	}
	
	public function success()
	{
		$this->end('Success');
	}
	
	public function error()
	{
		$this->end('Error');
	}
	
	private function end($message)
	{
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
  <head>
    <title>iframeform for phplister3</title>
    <style type="text/css">
html, body, *
{
	padding: 0;
	margin: 0;
	font-family: Arial, sans serif;
}
</style>
</head>
<body>
$message
</body>
</html>
HTML;
	exit;
	}
	
	public function unactivateMetadataPlugins()
	{
		return array();
	}
}
